(function(angular) {
	'use strict';
	angular.module('fs.waf').controller('cda.category.cate.nodeViewController', viewController);
	viewController.$inject = [ '$scope', '$q', 'Constants', 'gridService', 'modalService', 'layoutConfig', 'validatorConfig', 'authService', 'nodeService'];
	function viewController($scope, $q, Constants, gridService, modalService, layoutConfig, validatorConfig, authService, nodeService) {
		var ctrl = this, log = $scope.loggerFactory.getLogger("limitNodeView");
		var cateInfo = $scope.$stateParams.params;
		ctrl.layoutConfig = layoutConfig;
		ctrl.validatorConfig = validatorConfig;
		ctrl.cateInfo = cateInfo;
		ctrl.limitNode = {};
		ctrl.limitCategory = {};
		ctrl.init = function() {
			var params = {
					limitNodeId : cateInfo.id
				};			
				return authService.view(params).then(function(response) {
					ctrl.limitNode = response.data || cateInfo;
					nodeService.initOptions(ctrl);
				}, angular.noop);
			};
		
		function paginationChanged(pageNum, pageSize) {
			ctrl.searchCriteria.pageNum = pageNum;
			ctrl.searchCriteria.pageSize = pageSize;
			ctrl.searchCriteria.list = [];
			ctrl.search();
		}

		function rowSelectionChanged(eventRow, selectedRows) {
			ctrl.selectedRows = selectedRows;
		}

		function sortChanged(sortColumns) {
			// now just support sort by one column
			ctrl.searchCriteria.sortDirection = sortColumns[0] ? sortColumns[0].direction : '';
			ctrl.searchCriteria.sortBy = sortColumns[0] ? sortColumns[0].sortBy : '';
			ctrl.search();
		}
		
		ctrl.create = function() {
			$scope.go('cda.category.cate.nodeCreate', ctrl.limitNode);
		};
		ctrl.update = function() {
			$scope.go('cda.category.cate.nodeUpdate', ctrl.limitNode);
		};
		ctrl.delete = function() {
			$scope.go('cda.category.cate.nodeDelete', ctrl.limitNode);
		};
		ctrl.toCategoryList = function(){
			$scope.go('cda.category.cate');
		};
	};
})(angular);